using CfgTable;
using NetProtocol.POD;


namespace IQIGame.Onigao.GamePlay
{
    /// <summary>
    /// 关卡英雄的数据类
    /// </summary>
    public class DynLevelHero
    {
        public long id { protected set; get; }
        public int cid { protected set; get; }

        public CfgHero cfgHero { protected set; get; }
        public CfgHeroSkin cfgHeroSkin { protected set; get; }

        public int awakenLv { protected set; get; }
        public int level { protected set; get; }

        public int exp { protected set; get; }
        public int hp { protected set; get; }
        public int sp { protected set; get; }
        public int maxHp { protected set; get; }
        public int maxSp { protected set; get; }

        public LevelBuffHolder buffHolder { get; private set; }

        protected DynLevelHero()
        {
        }

        public virtual void InitByPOD(LevelHeroPOD pod)
        {
            this.id = pod.id;
            this.cid = pod.cid;
            this.awakenLv = pod.awakenLv;
            this.level = pod.level;
            this.exp = pod.exp;

            this.cfgHero = TableCenter.hero.Get(pod.cid);
            this.cfgHeroSkin = TableCenter.heroSkin.Get(pod.skinCid);

            this.hp = pod.hp;
            this.sp = pod.sp;
            this.maxHp = pod.maxHp;
            this.maxSp = pod.maxSp;

            buffHolder = new LevelBuffHolder(LevelBuffHostType.SingleHero, id);
        }

        public void RefreshHpSp(int hp, int sp)
        {
            this.hp = hp;
            this.sp = sp;
        }

        public void OnRevive()
        {
            buffHolder.Clear();
        }

        public static DynLevelHero CreateByPOD(LevelHeroPOD pod)
        {
            DynLevelHero levelHero = new DynLevelHero();
            levelHero.InitByPOD(pod);
            return levelHero;
        }
    }
}